<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="MobileOptimized" content="320" />
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/jiazai.css">
    <title>修改交易密码</title>
    <style>
        .notice-hea {
            position: fixed;
            top: 0;
            right: 0;
            left: 0;
            height: 40px;
            padding: 0 20px;
            display: flex;
            align-items: flex-end;
        }
        
        .notice-hea>span {
            margin-left: 18px;
            font-size: 17px;
        }
        
        .set-trans-wrap {
            position: fixed;
            top: 40px;
            left: 0;
            right: 0;
            bottom: 0;
            padding: 20px;
            overflow: auto;
        }
        
        .set-list {
            margin-top: 30px;
            padding: 8px 0;
            display: flex;
            align-items: center;
            font-size: 14px;
            border-bottom: 1px solid #eee;
        }
        
        .set-list>span {
            flex: 0 0 80px;
        }
        
        .set-list>input {
            flex: 1 1 0;
            letter-spacing: 2px;
        }
        
        .btn-sure {
            width: 70%;
            margin: 100px 15% 0;
            padding: 8px 0;
            font-size: 15px;
            letter-spacing: 2px;
            color: white;
            background: #3574FA;
            border-radius: 5px;
            box-shadow: 1px 1px 10px RGBA(53, 116, 250, .7);
        }
        
        .forget {
            padding-top: 20px;
            text-align: right;
            color: #3574FA;
        }
    </style>
</head>

<body>
    <div id='app'>

        <!-- 加载中动画 -->
        <div class='jiazai' v-if='jiazai'>
            <img src="./img/jia-ani.gif" width="50px" height="50px">
        </div>
        <!-- 加载中动画 -->

        <div class='notice-hea'>
            <img @click='close' src="./img/right-black.svg" width="20px" height="20px">
            <span>修改交易密码</span>
        </div>
        <div class='set-trans-wrap'>
            <div class='set-list'>
                <span>原密码</span>
                <input type="password" placeholder="请输入原密码" v-model='oldPass'>
            </div>
            <div class='set-list'>
                <span>新密码</span>
                <input type="password" placeholder="请输入6位数字" v-model='newPass'>
            </div>
            <!-- <p style="padding-top:10px;color:red;text-align:right;">请输入6位数字</p> -->
            <div class='set-list'>
                <span>确认密码</span>
                <input type="password" placeholder="再次确认密码" v-model='surePass'>
            </div>
            <p class='forget' @click="_openHref('forget-password.html', 'forgetPassword');">忘记密码?</p>
            <button class='btn-sure' @click='sure'>确认提交</button>
        </div>
    </div>
    <script src="js/comm.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/back.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/base64.js"></script>
    <script src="js/vue.min.js"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                //旧密码
                oldPass: '',
                //新密码
                newPass: '',
                //确认新密码
                surePass: ''
            },
            watch: {
                newPass: function(val) {
                    if (val.length < 6) {
                        return;
                    }
                    if (val.length != 6 || String(parseInt(val)).length != val.length) {
                        _toast('请输入6位数字作为交易密码');
                        this.newPass = '';
                    }
                },
                surePass: function(val) {
                    if (val.length < 6) {
                        return;
                    }
                    if (this.newPass != val) {
                        _toast('两次密码输入不一致');
                        this.surePass = '';
                    }
                }
            },
            methods: {
                close: function() {
                    var web = plus.webview.currentWebview();
                    web.close('none');
                },
                //修改交易密码提交
                sure: function() {
                    if (this.oldPass.length != 6 || String(parseInt(this.oldPass)).length != this.oldPass.length) {
                        _toast('原密码错误');
                        return;
                    }
                    if (this.newPass.length != 6 || String(parseInt(this.newPass)).length != this.newPass.length) {
                        _toast('请输入6位数字作为交易密码');
                        return;
                    }
                    if (this.newPass != this.surePass) {
                        _toast('两次密码输入不一致');
                        return;
                    }
                    this.jiazai = true;
                    var This = this;
                    _post(UPDATE_TRANS_PASS, {
                        userid: JSON.parse(localStorage.getItem('user')).userid,
                        ypassword: this.oldPass,
                        password1: this.newPass,
                        password2: this.surePass,
                        type: 2
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            _toast('修改交易密码成功');
                            setTimeout(function() {
                                plus.webview.currentWebview().close('none');
                            }, 1500);
                        } else {
                            _toast(data.msg);
                        }
                    });
                }
            }
        });
    </script>
    <script type="text/javascript" charset="utf-8">
        function plusReady() {

        }

        // 判断扩展API是否准备，否则监听'plusready'事件
        if (window.plus) {
            plusReady();
        } else {
            document.addEventListener('plusready', plusReady, false);
        }
    </script>
</body>

</html>